package com.common.base.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import com.common.CommonApplication;
import com.common.R;
import com.common.asynctask.TaskExecutor;
import com.common.bean.InfoResult;
import com.common.bean.MsgBean;
import com.common.bean.UserInfo;
import com.common.db.UserDao;
import com.common.logger.Logger;
import com.common.net.EasyHttp;
import com.common.net.callback.SimpleCallBack;
import com.common.net.exception.ApiException;
import com.common.net.model.HttpParams;
import com.common.okhttp.OkEntityListRequest;
import com.common.okhttp.OkEntityRequest;
import com.common.okhttp.OkHttpTask;
import com.common.okhttp.OkSimpleRequest;
import com.common.okhttp.SimpleOkHttpListener;
import com.common.ui.alerter.Alerter;
import com.common.ui.alerter.OnHideAlertListener;
import com.common.ui.alerter.OnShowAlertListener;
import com.common.ui.barlibrary.ImmersionBar;
import com.common.ui.barlibrary.OSUtils;
import com.common.ui.loadsir.callback.Callback;
import com.common.ui.loadsir.callback.EmptyCallback;
import com.common.ui.loadsir.callback.ErrorCallback;
import com.common.ui.loadsir.callback.LoadingCallback;
import com.common.ui.loadsir.callback.NoNetCallback;
import com.common.ui.loadsir.callback.SuccessCallback;
import com.common.ui.loadsir.callback.TimeoutCallback;
import com.common.ui.loadsir.core.Convertor;
import com.common.ui.loadsir.core.LoadService;
import com.common.ui.loadsir.core.LoadSir;
import com.common.ui.swipebacklayout.lib.SwipeBackLayout;
import com.common.ui.swipebacklayout.lib.app.SwipeBackActivity;
import com.okgo.OkGo;
import com.okgo.callback.StringCallback;
import com.okgo.model.Response;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Headers;

public abstract class BaseActivity  extends SwipeBackActivity {

    private ActivityManager activityManager = ActivityManager.getActivityManager();
    private EventBus eventBus;
    private Toast toast = null;
    private SwipeBackLayout swipeBackLayout;
    private InputMethodManager inputMethodManager;
    private static final int SUCCESS_CODE = 0x00;
    private static final int ERROR_CODE = 0x01;
    public LoadService loadService;
    private UserDao userDao;
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    InfoResult infoResult = (InfoResult) msg.obj;
                    int state = infoResult.getState();
                    if(state == -4){
                       onReLogin();
                    }else{
                        if(infoResult.isSuccess()){
                            int what = infoResult.getTag();
                            if(what == R.id.relogin){
                                UserInfo userInfo = (UserInfo) infoResult.getT();
                                CommonApplication.getInstance().setUserInfo(userInfo);
                                userDao.deleteAll();
                                userDao.add(userInfo);
                                loadData();
                            }else {
                                onSuccess(infoResult.getTag(),infoResult);
                            }
                        }else {
                            onFail(infoResult.getTag(),infoResult);
                        }
                    }
                    break;
                default:break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(null != activityManager) {
            activityManager.putActivity(this);
        }
        //初始化沉浸式
        initImmersionBar();
        //把设置布局文件的操作交给继承的子类
        setContentView(getLayoutResId());
        ButterKnife.bind(this);
        initSwipeBack();
        eventBus = EventBus.getDefault();
        eventBus.register(this);
        userDao = new UserDao(this);
        CommonApplication.getInstance().addActivity(this);
        if(isSupportLoadSirEnabled()!=null){
            initLoadSir(isSupportLoadSirEnabled());
        }
        init();
        loadData();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            CommonApplication.getInstance().finishActivity(this);
            //overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
            return true;
        }else {
            return super.onKeyDown(keyCode, event);
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        // 非必加
        // 如果你的app可以横竖屏切换，适配了华为emui3系列系统手机，并且navigationBarWithEMUI3Enable为true，
        // 请在onResume方法里添加这句代码（同时满足这三个条件才需要加上代码哦：1、横竖屏可以切换；2、华为emui3系列系统手机；3、navigationBarWithEMUI3Enable为true）
        // 否则请忽略
        if (OSUtils.isEMUI3_x() && isImmersionBarEnabled()) {
            ImmersionBar.with(this).init();
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (isImmersionBarEnabled()) {
            // 非必加
            // 如果你的app可以横竖屏切换，适配了4.4或者华为emui3.1系统手机，并且navigationBarWithKitkatEnable为true，
            // 请务必在onConfigurationChanged方法里添加如下代码（同时满足这三个条件才需要加上代码哦：1、横竖屏可以切换；2、android4.4或者华为emui3.1系统手机；3、navigationBarWithKitkatEnable为true）
            // 否则请忽略
            ImmersionBar.with(this).init();
        }
    }

    @Override
    public void finish() {
        super.finish();
        hideSoftKeyBoard();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        inputMethodManager = null;
        if(eventBus!=null){
            eventBus.unregister(this);
        }
        if(null != activityManager) {
            activityManager.removeActivity(this);
        }
        if (isImmersionBarEnabled()) {
            ImmersionBar.with(this).destroy();
        }
        ButterKnife.bind(this).unbind();
        CommonApplication.getInstance().finishActivity(this);
    }

    /**
     * 设置Activity的显示方向为横向
     *
     * @param activity
     */
    @SuppressLint("SourceLockedOrientationActivity")
    public void setScreenHorizontal(Activity activity) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

    /**
     * 设置Activity的显示方向为垂直方向
     *
     * @param activity
     */
    @SuppressLint("SourceLockedOrientationActivity")
    public void setScreenVertical(Activity activity) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void handlerMeg(MsgBean msgBean) {

    }

    protected void initImmersionBar() {
        if (isImmersionBarEnabled()) {
            //在BaseActivity里初始化
            ImmersionBar.with(this).init();
            ImmersionBar.with(this).navigationBarColor(R.color.white).init();
        }else {
            //initSystemBarTint();
        }
    }

    private void initSwipeBack(){
        if(isSupportSwipeBackEnabled()){
            // 可以调用该方法，设置是否允许滑动退出
            setSwipeBackEnable(true);
            swipeBackLayout = getSwipeBackLayout();
            // 设置滑动方向，可设置EDGE_LEFT, EDGE_RIGHT, EDGE_ALL, EDGE_BOTTOM
            swipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
            // 滑动退出的效果只能从边界滑动才有效果，如果要扩大touch的范围，可以调用这个方法
            //swipeBackLayout.setEdgeSize(200);
        }else {
            setSwipeBackEnable(false);
        }
    }

    public abstract View isSupportLoadSirEnabled();

    public void initLoadSir(View loadSirView){
        LoadSir loadSir = new LoadSir.Builder()
                .addCallback(new LoadingCallback())
                .addCallback(new EmptyCallback())
                .addCallback(new TimeoutCallback())
                .addCallback(new ErrorCallback())
                .addCallback(new NoNetCallback())
                //.setDefaultCallback(SuccessCallback.class)
                .setDefaultCallback(LoadingCallback.class)
                .build();
        loadService = loadSir.register(loadSirView, new Callback.OnReloadListener() {
            @Override
            public void onReload(View v) {
                loadService.showCallback(LoadingCallback.class);
                loadData();
            }
        });
    }

    private void initLoadSir(){
        LoadSir loadSir = new LoadSir.Builder()
                .addCallback(new LoadingCallback())
                .addCallback(new NoNetCallback())
                .addCallback(new TimeoutCallback())
                .addCallback(new EmptyCallback())
                .addCallback(new ErrorCallback())
                .setDefaultCallback(LoadingCallback.class)
                .build();
        loadService = loadSir.register(this, new Callback.OnReloadListener() {
            @Override
            public void onReload(View v) {
                loadService.showCallback(LoadingCallback.class);
                // 重新加载逻辑
            }
        }, new Convertor<InfoResult>() {
            @Override
            public Class<? extends Callback> map(InfoResult infoResult) {
                Class<? extends Callback> resultCode = SuccessCallback.class;
                switch (infoResult.getState()) {
                    //success
                    case SUCCESS_CODE:
                        if (infoResult.getState() == 1) {
                            resultCode = SuccessCallback.class;
                        } else {
                            resultCode = EmptyCallback.class;
                        }
                        break;
                    case ERROR_CODE:
                        resultCode = ErrorCallback.class;
                        break;
                    default:
                        resultCode = ErrorCallback.class;
                }
                return resultCode;
            }
        });
    }

    //-------------------------- okhttp -----------------------------//

    public <T> void requestOkhttpEntityList(OkEntityListRequest<T> okEntityListRequest){
        SimpleOkHttpListener simpleOkHttpListener = new SimpleOkHttpListener(){
            @Override
            public void dataSucceed(int what, InfoResult t) {
                super.dataSucceed(what, t);
                t.setTag(what);
                Message msg = handler.obtainMessage();
                msg.what = 0;
                msg.obj = t;
                handler.sendMessage(msg);
            }

            @Override
            public void dataFailed(int what, InfoResult t) {
                super.dataFailed(what, t);
                t.setTag(what);
                Message msg = handler.obtainMessage();
                msg.what = 0;
                msg.obj = t;
                handler.sendMessage(msg);
            }
        };
        OkHttpTask okHttpTask = new OkHttpTask(okEntityListRequest,simpleOkHttpListener);
        TaskExecutor.getInstance().start(okHttpTask);
    }

    public <T> void requestOkhttpEntity(OkEntityRequest<T> okEntityRequest){
        SimpleOkHttpListener simpleOkHttpListener = new SimpleOkHttpListener(){
            @Override
            public void dataSucceed(int what, InfoResult t) {
                super.dataSucceed(what, t);
                t.setTag(what);
                Message msg = handler.obtainMessage();
                msg.what = 0;
                msg.obj = t;
                handler.sendMessage(msg);
            }

            @Override
            public void dataFailed(int what, InfoResult t) {
                super.dataFailed(what, t);
                t.setTag(what);
                Message msg = handler.obtainMessage();
                msg.what = 0;
                msg.obj = t;
                handler.sendMessage(msg);
            }
        };
        OkHttpTask okHttpTask = new OkHttpTask(okEntityRequest,simpleOkHttpListener);
        TaskExecutor.getInstance().start(okHttpTask);
    }

    public <T> void requestOkhttpSimple(OkSimpleRequest<T> tOkSimpleRequest){
        SimpleOkHttpListener simpleOkHttpListener = new SimpleOkHttpListener(){
            @Override
            public void dataSucceed(int what, InfoResult t) {
                super.dataSucceed(what, t);
                t.setTag(what);
                Message msg = handler.obtainMessage();
                msg.what = 0;
                msg.obj = t;
                handler.sendMessage(msg);
            }

            @Override
            public void dataFailed(int what, InfoResult t) {
                super.dataFailed(what, t);
                t.setTag(what);
                Message msg = handler.obtainMessage();
                msg.what = 0;
                msg.obj = t;
                handler.sendMessage(msg);
            }
        };
        OkHttpTask okHttpTask = new OkHttpTask(tOkSimpleRequest,simpleOkHttpListener);
        TaskExecutor.getInstance().start(okHttpTask);
    }

    //===================================alerter==========================================
    public void showAlert(String msg){
        Alerter.create(this)
                .setText(msg)
                .disableOutsideTouch()
                .setDuration(700)
                .show();
    }

    private void showAlertDefault() {
        Alerter.create(this)
                .setTitle("Alert Title")
                .setText("Alert text...")
                .disableOutsideTouch()
                .show();
    }

    private void showAlertColoured() {
        Alerter.create(this)
                .setTitle("Alert Title")
                .setText("Alert text...")
                .setBackgroundColor(R.color.colorAccent)
                .show();
    }

    private void showAlertWithIcon() {
        Alerter.create(this)
                .setText("Alert text...")
                .setIcon(R.drawable.alerter_ic_face)
                .show();
    }

    private void showAlertTextOnly() {
        Alerter.create(this)
                .setText("Alert text...")
                .show();
    }

    private void showAlertWithOnClick() {
        Alerter.create(this)
                .setTitle("Alert Title")
                .setText("Alert text...")
                .setDuration(10000)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Toast.makeText(BaseActivity.this, "OnClick Called", Toast.LENGTH_LONG).show();
                    }
                })
                .show();
    }

    private void showAlertVerbose() {
        Alerter.create(BaseActivity.this)
                .setTitle("Alert Title")
                .setText("The alert scales to accommodate larger bodies of text. " +
                        "The alert scales to accommodate larger bodies of text. " +
                        "The alert scales to accommodate larger bodies of text.")
                .show();
    }

    private void showAlertCallbacks(){
        Alerter.create(BaseActivity.this)
                .setTitle("Alert Title")
                .setText("Alert text...")
                .setDuration(10000)
                .setOnShowListener(new OnShowAlertListener() {
                    @Override
                    public void onShow() {
                        Toast.makeText(BaseActivity.this, "Show Alert", Toast.LENGTH_LONG).show();
                    }
                })
                .setOnHideListener(new OnHideAlertListener() {
                    @Override
                    public void onHide() {
                        Toast.makeText(BaseActivity.this, "Hide Alert", Toast.LENGTH_LONG).show();
                    }
                })
                .show();
    }

    private void showAlertInfiniteDuration() {
        Alerter.create(BaseActivity.this)
                .setTitle("Alert Title")
                .setText("Alert text...")
                .enableInfiniteDuration(true)
                .show();
    }

    //===================================EasyHttp==========================================
    public <T> void requestOkhttpEntityList(String url, HttpParams params){
        EasyHttp.post(url)
                .params(params)
                .execute(new SimpleCallBack<T>() {
                    @Override
                    public void onError(ApiException e) {

                    }

                    @Override
                    public void onSuccess(T t) {
                    }
                });
    }

    //===================================okgo==========================================
    public<T> void requestString(String url,int tag){
        OkGo.<String>get(url)
                .tag(tag)
                //.headers("header1", "headerValue1")//
                //.params("param1", "paramValue1")//
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                    }

                    @Override
                    public void onError(Response<String> response) {

                    }

                });
    }

    //===================================showToast=====================================
    public void showToast(String msg) {
        if (toast == null) {
            toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
        } else {
            toast.setText(msg);
        }
        toast.show();
    }

    public int getColor(Context context, int id) {
        return ContextCompat.getColor(context, id);
    }

    public void hideSoftKeyBoard() {
        View localView = getCurrentFocus();
        if (this.inputMethodManager == null) {
            this.inputMethodManager = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
        }
        if ((localView != null) && (this.inputMethodManager != null)) {
            this.inputMethodManager.hideSoftInputFromWindow(localView.getWindowToken(), 2);
        }
    }
    /**
     * 跳转到某个Activity
     * @param activity
     * @param targetActivity
     */
    public void switchTo(Activity activity, Class<? extends Activity> targetActivity, boolean finish) {
        switchTo(activity, new Intent(activity, targetActivity),finish);
    }

    public void switchTo(Activity activity, Intent intent, boolean finish) {
        activity.startActivity(intent);
        if(finish){
            finish();
        }
        //overridePendingTransition(R.anim.alpha_out, R.anim.alpha_in);
    }

    /**
     * 跳转到权限设置界面
     */
    public void goIntentSetting() {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= 9) {
            intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
            intent.setData(Uri.fromParts("package", getPackageName(), null));
        } else if (Build.VERSION.SDK_INT <= 8) {
            intent.setAction(Intent.ACTION_VIEW);
            intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
            intent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());
        }
        startActivity(intent);
    }

    /** 子类可以重写决定是否使用透明状态栏 */
    protected boolean translucentStatusBar() {
        return false;
    }

    /** 设置状态栏颜色 */
    protected void initSystemBarTint() {
        Window window = getWindow();
        if (translucentStatusBar()) {
            // 设置状态栏全透明
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(Color.TRANSPARENT);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }
            return;
        }
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //5.0以上使用原生方法
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(setStatusBarColor());
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //4.4-5.0使用三方工具类，有些4.4的手机有问题，这里为演示方便，不使用沉浸式
            //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }
    //===================================progressDialog=====================================
    private Dialog progressDialog;
    private TextView tipTextView;
    public void showProgress(String message) {
        showProgress(message, true);
    }

    public void showProgress(String message, boolean cancelable) {
        if (progressDialog == null) {
            progressDialog = createLoadingDialog(message);
        }
        else if (progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
        if (!TextUtils.isEmpty(message)) {
            tipTextView.setText(message);
        }
        else {
            tipTextView.setText(getString(R.string.load_text));
        }
        progressDialog.setCancelable(cancelable);
        progressDialog.show();
    }

    /**
     * 得到自定义的progressDialog
     *
     * @param msg
     * @return
     */
    private Dialog createLoadingDialog(String msg) {
        LayoutInflater inflater = LayoutInflater.from(this);
        View v = inflater.inflate(R.layout.dialog_loading,
                null);
        tipTextView = (TextView) v.findViewById(R.id.tipTextView);
        if (!TextUtils.isEmpty(msg)) {
            tipTextView.setText(msg);
        }
        Dialog loadingDialog = new Dialog(this,
                R.style.loading_dialog);
        loadingDialog.setCancelable(true);
        loadingDialog.setCanceledOnTouchOutside(false);
        loadingDialog.setContentView(v);
        return loadingDialog;
    }

    public void hideProgress() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

    private Dialog loading_dialog;
    public void showDialog(String message){
        loading_dialog = new AlertDialog.Builder(this).setMessage(message).create();
        loading_dialog.show();
    }

    public void hideDialog(){
        if(loading_dialog!=null){
            loading_dialog.dismiss();
        }
    }

    /** 子类可以重写改变状态栏颜色 */
    protected int setStatusBarColor() {
        return R.color.colorPrimary;
    }

    // -------------------- BaseActivity的辅助封装 --------------------- //

    public abstract boolean isImmersionBarEnabled();
    /**
     * 是否支持滑动返回
     *
     * @return
     */
    public abstract boolean isSupportSwipeBackEnabled();

    /**
     * 返回当前Activity布局文件的id
     *
     * @return
     */
    public abstract int getLayoutResId();

    /**
     * 初始化的一些操作
     */
    public abstract void init();

    /**
     * 加载网络数据
     */
    public abstract void loadData();

    /**
     * 网络数据返回成功
     */
    protected abstract void onSuccess(int what, InfoResult t);

    /**
     * 网络数据返回失败
     */
    protected abstract void onFail(int what,InfoResult t);

    public EventBus getEventBus() {
        return eventBus;
    }

    protected <T> void handleResponse(Response<T> response) {
        StringBuilder sb;
        Call call = response.getRawCall();
        if (call != null) {
            Logger.d("okgo","请求成功  请求方式：" + call.request().method() + "\n" + "url：" + call.request().url());
            Headers requestHeadersString = call.request().headers();
            Set<String> requestNames = requestHeadersString.names();
            sb = new StringBuilder();
            for (String name : requestNames) {
                sb.append(name).append(" ： ").append(requestHeadersString.get(name)).append("\n");
            }
            Logger.d("okgo","请求头内容:" + sb.toString());
        } else {
            Logger.d("okgo","--");
        }
        T body = response.body();
        if (body == null) {

        } else {
            if (body instanceof String) {
                //responseData.setText((String) body);
            } else if (body instanceof List) {
                sb = new StringBuilder();
                List list = (List) body;
                for (Object obj : list) {
                    sb.append(obj.toString()).append("\n");
                }
                //responseData.setText(sb.toString());
            } else if (body instanceof Set) {
                sb = new StringBuilder();
                Set set = (Set) body;
                for (Object obj : set) {
                    sb.append(obj.toString()).append("\n");
                }
                //responseData.setText(sb.toString());
            } else if (body instanceof Map) {
                sb = new StringBuilder();
                Map map = (Map) body;
                Set keySet = map.keySet();
                for (Object key : keySet) {
                    sb.append(key.toString()).append(" ： ").append(map.get(key)).append("\n");
                }
                //responseData.setText(sb.toString());
            } else if (body instanceof File) {
                File file = (File) body;
                //responseData.setText("数据内容即为文件内容\n下载文件路径：" + file.getAbsolutePath());
            } else if (body instanceof Bitmap) {
                //responseData.setText("图片的内容即为数据");
            } else {
                //responseData.setText(Convert.formatJson(body));
            }
        }

        okhttp3.Response rawResponse = response.getRawResponse();
        if (rawResponse != null) {
            Headers responseHeadersString = rawResponse.headers();
            Set<String> names = responseHeadersString.names();
            sb = new StringBuilder();
            sb.append("url ： ").append(rawResponse.request().url()).append("\n\n");
            sb.append("stateCode ： ").append(rawResponse.code()).append("\n");
            for (String name : names) {
                sb.append(name).append(" ： ").append(responseHeadersString.get(name)).append("\n");
            }
            //responseHeader.setText(sb.toString());
        } else {
            //responseHeader.setText("--");
        }
    }

    public void onReLogin(){

    }
}
